﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PrimaryAlgorithm.IsPowerOfThree
{
    class MainProject
    {
        static void Main(string[] args)
        {
            Console.WriteLine(IsPowerOfThree(27));
            Console.WriteLine(Math.Log(243, 3));
            Console.ReadKey();
        }


        /// <summary>
        /// 4.999 接受的值是4.999~ 但是最后输出的是5
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static bool IsPowerOfThree(int n)
        {
            double a = Math.Log10(n);
            double b = Math.Log10(3);
            double c = Math.Log10(n)/Math.Log10(3);
            return (Math.Log10(n) / Math.Log10(3)) % 1 == 0;

            //会造成精度问题
            //double s = Math.Log(n, 3);
            //if (n==0) return false;
            //return !s.ToString().Contains('.');
        }
    }
}
